#========================================================
#Created on 31/ago/2009
#
#@author: Fabio
#========================================================
from PyQt4 import QtCore, QtGui, QtXml
from HomeTreeModel import DomModel

class HomeView( QtGui.QFrame ):
    def __init__( self, parent = None ):
        super( HomeView, self ).__init__( parent )


        self.model = DomModel( QtXml.QDomDocument(), self )
        self.xmlPath = ""
        self.view = QtGui.QTreeView( self )
        self.view.setModel( self.model )
        self.view.setIndentation( 15 )

        layout = QtGui.QVBoxLayout()
        layout.addWidget( self.view )
        self.setLayout( layout )


    def openFile( self ):
        filePath = QtGui.QFileDialog.getOpenFileName( self,
                self.tr( "Open File" ), self.xmlPath,
                self.tr( "XML files (*.xml);;HTML files (*.html);;"
                        "SVG files (*.svg);;User Interface files (*.ui)" ) )

        if filePath:
            f = QtCore.QFile( filePath )
            if f.open( QtCore.QIODevice.ReadOnly ):
                document = QtXml.QDomDocument()
                if document.setContent( f ):
                    newModel = DomModel( document, self )
                    self.view.setModel( newModel )
                    self.model = newModel
                    self.xmlPath = filePath

                f.close()
